﻿using System.Collections.Generic;
using MDK.Common;
using System.Drawing;

namespace MDK.Device
{
    public static class FlowEventHelper
    {
        /// <summary>
        /// 交接状态改变(true 可放托 false 不可放托)
        /// </summary>
        public const string HandoverStateChangedEventName = "HandoverStateChanged";
        public const string InputBarcodeEventName = "InputBarcode";
        public const string DeviceScrammedEventName = "DeviceScrammed";
        public const string EndHandoverName = "EndHandover";

        public static Dictionary<string, object> SendMessage(HandoverStateChangedArgs args, SystemModel SysModel)
        {
            var arg = new Dictionary<string, object>()
            {
                {"arg", args},
            };
            //开启警报
            SysModel.Freezer.Alert.TurnOn();
            SysModel.Front.Alert.TurnOn();

            EventHelper.Rasie(HandoverStateChangedEventName, arg);
            //关闭警报

            SysModel.Freezer.Alert.TurnOff();
            SysModel.Front.Alert.TurnOff();
            return arg;
        }

        public static void InputBarcode(Pallet pallet)
        {
            EventHelper.Rasie(InputBarcodeEventName, new Dictionary<string, object>
            {
                {"pallet", pallet}
            });
        }

        public static void EndHandover()
        {
            EventHelper.Rasie(EndHandoverName, new Dictionary<string, object>
            {
            });
        }

        public static bool OnScrammed(IPlcDevice device)
        {
            var arg = new Dictionary<string, object>
            {
                {"device", device}
            };
            EventHelper.Rasie(DeviceScrammedEventName, arg);
            return (bool)arg["continue"];
        }
    }

    public class HandoverStateChangedArgs
    {
        public FlowMesssages Code { get; set; }
        public string Message { get; set; }
        public string Detail { get; set; }
        public TubeTypes[] Types { get; set; }
    }

    public enum FlowMesssages
    {
        AtmMsgBase = 0,
        AtmBeltScanCompleted,
        AtmBeltScanFailed,
        AtmBeltEndSensorException,
        AtmDropPalletTooEarly,
        AtmIdentifyTubeSuccess,
        AtmIdentifyTubeFail,
        AtmDoorHasAnything,

        FrontMsgBase = 100,
        FrontPositionOutSync,
        FrontPositionUseUp,
        FrontBalanceFailed,
        EmptyPalletUseUp
    }
}
